import { Component, OnInit, Injector, ViewChild, Output, EventEmitter, Input } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ModalDirective } from 'ngx-bootstrap';
import {
    EditDtoExtensionsItem,
    StockZT_BaseInfoServiceProxy,
    Stock_BaseFieldListDto
} from '@shared/service-proxies/stock-service-proxies';
// import { ToolingZT_BaseInfoServiceProxy, Stock_ToolingBaseFieldListDto } from '@shared/service-proxies/tooling-service-proxies';

@Component({
    selector: 'toolingBaseFieldDetailModal',
    templateUrl: './tooling-basefield-detail-modal.component.html',
    styleUrls: ['./tooling-basefield-detail-modal.component.less']
})
export class ToolingBaseFieldDetailModalComponent extends AppComponentBase implements OnInit {
    constructor(injector: Injector, private _stockZT_BaseInfoServiceProxy: StockZT_BaseInfoServiceProxy) {
        super(injector);
    }

    @ViewChild('createOrEditModal') modal: ModalDirective;

    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Input() stocktype;
    active = false;
    saving = false;
    _type;
    selectedValue = new Stock_BaseFieldListDto();
    editDto;
    extensions: Array<EditDtoExtensionsItem>;
    extendextensions: Array<EditDtoExtensionsItem>;
    optionAll;
    itemcode = '';
    ngOnInit(): void {}
    showinfo(id?: string, type?: string, codeItemId?: string): void {
        this.active = true;
        this._type = type;
        console.log(id);
        switch (this._type) {
            case '工装':
                this._stockZT_BaseInfoServiceProxy.getToolingDtoExtensionsById(id, '').subscribe(result => {
                    this.optionAll = {
                        f_DimensionGroupIDOptions: result.dimentionSelectOptions,
                        f_UnitIdOptions: result.unitIdSelectOptions
                    };
                    this.editDto = result.toolingOutput;
                    this.extendextensions = result.extendItems;
                    //  this.extensions = result.baseItems;
                    this.editDto.f_StockType = this._type;
                    this.extendextensions.forEach(el => {
                        el.readonly = true;
                    });
                    // this.extensions.forEach(el => {
                    //     el.readonly = true;
                    // });
                    this.modal.show();
                });
                break;
        }
    }

    save(): void {}

    close(): void {
        this.active = false;
        this.modal.hide();
    }
}
